package com.darker.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @auther lj
 * @date 2018/5/3 16:34
 * @email lmwtuedu@163.com
 */
public class MyInvocation implements InvocationHandler {
    // 切面对象
    private Advice advice;
    // 被代理对象，即目标属性
    private Object target;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        advice.beforeMethod(method);
        Object obj = method.invoke(target, args);
        advice.afterMethod(method);

        return obj;
    }

    public Advice getAdvice() {
        return advice;
    }

    public void setAdvice(Advice advice) {
        this.advice = advice;
    }

    public Object getTarget() {
        return target;
    }

    public void setTarget(Object target) {
        this.target = target;
    }
}
